package com.aaa.dao.impl;

import com.aaa.dao.EmpDao;
import com.aaa.entity.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/8/23 9:01
 * @description：
 * @modified By：
 * @version:
 */
@Repository
public class EmpDaoImpl  implements EmpDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public List<Map<String, Object>> findAll() {
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList("select * from emp ");
        return mapList;
    }

    public List<Emp> findAllEmp() {
        List<Emp> empList = jdbcTemplate.query("select * from emp ", new BeanPropertyRowMapper<Emp>(Emp.class));
        return empList;
    }

    public int deleteById(Integer id) {
        return jdbcTemplate.update("delete  from emp where empno=?",id);
    }
}
